import QtQuick 1.0
import "../Components"


DialogBase {
    id: _root
    width: parent.width
    height: parent.height
    x: 0
    y: 0

    dialogTitle: "Setting"

    function viewEvent(){
        loadSetting();
    }

    // 設定を反映する
    function applySetting(){
        _globalSetting.updateInterval = _intervalText.text;
        _globalSetting.inReplyCountMax = _inReplyToCountMaxText.text;
    }

    // 設定を読み込む
    function loadSetting(){
        _intervalText.text = _globalSetting.updateInterval.toString();
        _inReplyToCountMaxText.text = _globalSetting.inReplyCountMax.toString();
    }

    // パラメータチェック
    function checkValues(){
        var ret = true;

        // 更新間隔
        if(_intervalText.text < 30){
            _toast.show("Please set 30 seconds or more at the update interval.")
            ret = false;
        }
        // in reply toの読込み数
        if(_inReplyToCountMaxText.text < 1){
            _toast.show("Please input a positive number.");
            ret = false;
        }

        return ret;
    }

    // 更新間隔
    Item{
        id: _intervalArea
        height: _intervalText.height
        anchors.top: parent.titleBottom
        anchors.topMargin: 10
        anchors.left: parent.left
        anchors.leftMargin: 10
        anchors.right: parent.right
        anchors.rightMargin: 10

        Text {
            id: _intervalLabel
            anchors.left: parent.left
            height: parent.height
            verticalAlignment: Text.AlignVCenter

            text: "Update interval(sec) : "
            color: "#ffffff"
        }

        TextBox {
            id: _intervalText
            width: 100
            height: 20
            anchors.left: _intervalLabel.right
            anchors.top: parent.top
            anchors.leftMargin: 5

            text: "10"
        }

    }

    // in reply to の取得回数
    Item{
        id: _inReplyToCountMaxArea
        height: _inReplyToCountMaxText.height
        anchors.top: _intervalArea.bottom
        anchors.topMargin: 10
        anchors.left: parent.left
        anchors.leftMargin: 10
        anchors.right: parent.right
        anchors.rightMargin: 10

        Text {
            id: _inReplyToCountMaxLabel
            anchors.left: parent.left
            height: parent.height
            verticalAlignment: Text.AlignVCenter

            text: "Max to get \'in reply to\'(times) : "
            color: "#ffffff"
        }

        TextBox {
            id: _inReplyToCountMaxText
            width: 100
            height: 20
            anchors.left: _inReplyToCountMaxLabel.right
            anchors.top: parent.top
            anchors.leftMargin: 5
        }

    }

    Row {
        id: _areaButton
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 10
        anchors.horizontalCenter: parent.horizontalCenter


        spacing: 5

        Button {
            id: _buttonOk
            width: 100
            height: 25

            text: "O K"

            onClicked : {
//                clickOkButton();
                if(checkValues()){
                    applySetting();
                    _menuContainer.state = "";
                }
            }
        }

        Button {
            id: _buttonCancel
            width: 100
            height: 25

            text: "Cancel"

            onClicked : {
                _menuContainer.state = "";
            }
        }
    }

}
